/*******************************************************************************
 * Package: com.hngtrust.iir.user.controller
 * Type:    SearchHistoryController
 * Date:    2021-8-13 8:57
 *
 * Copyright (c) 2021 HUANENG GUICHENG TRUST CORP.,LTD All Rights Reserved.
 *
 * You may not use this file except in compliance with the License.
 *******************************************************************************/
package com.hngtrust.iir.user.controller;

import com.hngtrust.framework.bind.ResponseInfo;
import com.hngtrust.framework.security.util.SecurityUtils;
import com.hngtrust.iir.user.controller.dto.AddHistoryReqVO;
import com.hngtrust.iir.user.controller.dto.ListHistoryReqVO;
import com.hngtrust.iir.user.entity.SearchHistory;
import com.hngtrust.iir.user.entity.User;
import com.hngtrust.iir.user.service.SearchHisService;
import com.hngtrust.iir.user.service.SearchHistoryService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.util.List;

/**
 * 搜索历史
 * @author Chentianyong
 * @date 2021-8-13 8:57
 */
@Slf4j
@Api(tags = "搜索历史")
@RestController
@RequestMapping("/search-history")
public class SearchHistoryController {
    @Autowired
    private SearchHistoryService searchHistoryService;

    @Autowired
    private SearchHisService searchHisService;

    
    @ApiOperation("搜索历史列表")
    @PostMapping("/list-history")
    public ResponseInfo<List<SearchHistory>> listHistory(@ApiParam(value = "列表参数") @Valid @RequestBody ListHistoryReqVO vo){
        User loginUser = (User) SecurityUtils.getLoginUser().getAdditionalInfo();
        SearchHistory req = new SearchHistory();
        req.setDataType(vo.getDataType());
        req.setUserId(loginUser.getId());
        req.setSearchKey(vo.getSearchKey());
        List<SearchHistory> query = searchHistoryService.listHistory(req);
        return new ResponseInfo<List<SearchHistory>>(query);
    }
    
    @ApiOperation("添加搜索历史")
    @PostMapping("/add-history")
    public ResponseInfo<Object> addHistory(@ApiParam(value = "添加参数") @Valid @RequestBody AddHistoryReqVO vo){
        searchHisService.addHistory(vo);
    
        return new ResponseInfo<>();
    }
}
